package org.scboy.dbms.controller;

import org.scboy.common.annotation.Menu;
import org.scboy.common.annotation.Permission;
import org.scboy.common.request.Result;
import org.scboy.dbms.service.RequestValidService;
import org.scboy.utils.entitys.coobi.Model;
import org.scboy.utils.entitys.coobi.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController("base_RequestValidController")
@RequestMapping("/base/requestvalid/")
@Menu("微服务管理系统.验证配置")
public class RequestValidController {
	
	@Autowired
	RequestValidService service;
	
	@PostMapping("page")
	@Permission("分页查询")
	public Result page(@RequestBody Model params){
		Page page=service.page(params);
		return Result.Success(page.getData(), page.getCount());
	}
	
	/**
	 * 新增文件字典
	 * @param request
	 * @return
	 */
	@PostMapping("add")
	@Permission("新增配置")
	public Result add(@RequestBody Model params){
		if(service.add(params)){
			return Result.Success("BASE_REQUEST_VALID_ADD_SUCCESS");
		}else{
			return Result.Error("BASE_REQUEST_VALID_ADD_ERROR");
		}
	}
	
	/**
	 * 获取字典
	 * @param request
	 * @return
	 */
	@GetMapping("get")
	@Permission("获取配置详情")
	public Result get(String id){
		return Result.Success(service.get(id),"");
	}
	
	/**
	 * 更新字典
	 * @param request
	 * @return
	 */
	@PutMapping("update")
	@Permission("更新配置")
	public Result update(@RequestBody Model params){
		if(service.update(params)){
			return Result.Success("BASE_REQUEST_VALID_UPDATE_SUCCESS");
		}else{
			return Result.Error("BASE_REQUEST_VALID_UPDATE_ERROR");
		}		
	}

	/**
	 * 删除字典
	 * @param request
	 * @return
	 */
	@DeleteMapping("delete")
	@Permission("删除配置")
	public Result delete(String id){
		if(service.delete(id)){
			return Result.Success("BASE_REQUEST_VALID_DELETE_SUCCESS");
		}else{
			return Result.Error("BASE_REQUEST_VALID_DELETE_ERROR");
		}
	}
	

	/**
	 * 启用禁用
	 * @param request
	 * @param id
	 * @return
	 */
	@PutMapping("checkstate")
	@Permission("启用禁用")
	public Result checkState(String id){
		if(service.checkState(id)){
			return Result.Success("BASE_REQUEST_VALID_CHECKSTATE_SUCCESS");
		}else{
			return Result.Error("BASE_REQUEST_VALID_CHECKSTATE_ERROR");
		}
	}
	

	@GetMapping("rules")
	@Permission("验证列集合")
	public Result rules(String url,String code){
		return Result.Success(service.rules(url, code));
	}
	
	@PutMapping("copy")
	@Permission("复制配置")
	public Result copy(String id){
		if(service.copy(id)){
			return Result.Success("BASE_REQUEST_VALID_COPY_SUCCESS");
		}else{
			return Result.Error("BASE_REQUEST_VALID_COPY_ERROR");
		}
	}
	
}
